home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / VideoToolbox 94.11.17 / VideoToolboxSources / HideMenuBar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-15  |  4.1 KB  |  148 lines  |  [TEXT/KAHL]

  1. /*
  2. HideMenuBar.c
  3.  
  4. Based on:
  5.  
  6. "Code gadgets: Hiding the menu bar", THINKin' CaP, 1(2):28-29, Fall 1990.
  7. Copyright © 1991 SPLAsh Resources.
  8.  
  9. and
  10.  
  11. Symantec THINK Reference 2, "How to Hide the MenuBar".
  12.  
  13. HISTORY:
  14. 2/28/91 dgp added to VideoToolbox
  15. 8/24/91    dgp    Made compatible with THINK C 5.
  16. 1/25/93 dgp removed obsolete support for THINK C 4.
  17. 1/25/93    dgp Replaced SysEqu.h by LoMem.h and changed program accordingly.
  18. 2/23/93    dgp    Call CopyQuickDrawGlobals to make sure qd is valid.
  19. 2/27/93    dgp Edited the code and comments, partly copying from THINK Reference's
  20.             suggestion for how to do this. This was prompted by David Brainard's
  21.             report that these routines were crashing when called within the
  22.             MATLAB environment. The main changes are to also call
  23.             CalcVisBehind() after restoring, and to use DiffRgn
  24.             to restore by cutting the menu bar back out of the desktop
  25.             instead of restoring by copying from a saved copy of the region. 
  26. 3/3/93    dgp    Added SquareCorners and RestoreCorners, with support for 1-bit quickdraw.
  27. 10/8/94    dgp    Made compatible with Apple's new Universal Headers and PowerPC.
  28. */
  29. #include "VideoToolbox.h"
  30. #include <Menus.h>
  31. #if UNIVERSAL_HEADERS
  32.     #include <LowMem.h>
  33. #else
  34.     #define LMGetMBarHeight() (* (short *) 0x0BAA)
  35.     #define LMSetMBarHeight(MBarHeightValue) ((* (short *) 0x0BAA) = (MBarHeightValue))
  36. #endif
  37.  
  38. static short oldMBarHeight;                    // Pixel height of the menu bar
  39. static RgnHandle mBarRgn=NULL;                // Region encompassing the menu bar
  40. static RgnHandle cornerRgn[MAX_SCREENS];
  41.  
  42. void HideMenuBar(void)
  43. {
  44.     Rect r;
  45.     
  46.     if (LMGetMBarHeight()>0) {
  47.         mBarRgn=NewRgn();
  48.         CopyQuickDrawGlobals();                // Make sure qd is valid
  49.         r=qd.screenBits.bounds;
  50.         r.bottom=r.top+LMGetMBarHeight();
  51.         RectRgn(mBarRgn,&r);
  52.         oldMBarHeight=LMGetMBarHeight();
  53.         LMSetMBarHeight(0);
  54.         UnionRgn(GetGrayRgn(),mBarRgn,GetGrayRgn());
  55.         PaintOne(NULL,mBarRgn);
  56.         CalcVisBehind((WindowPeek)FrontWindow(),mBarRgn);
  57.     }
  58. }
  59.  
  60. void ShowMenuBar(void)
  61. {
  62.     if(LMGetMBarHeight()==0 && mBarRgn!=NULL){
  63.         LMSetMBarHeight(oldMBarHeight);
  64.         DiffRgn(GetGrayRgn(),mBarRgn,GetGrayRgn());
  65.         DrawMenuBar();
  66.         CalcVisBehind((WindowPeek)FrontWindow(),mBarRgn);
  67.         DisposeRgn(mBarRgn);
  68.         mBarRgn=NULL;
  69.     }
  70. }
  71.  
  72. void SquareCorners(GDHandle device)
  73. // Extend GrayRgn to include this screen's corners, which otherwise might be rounded off.
  74. // If NULL then applies to all screens.
  75. {
  76.     int i;
  77.     Rect r;
  78.     long quickDraw;
  79.     
  80.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  81.     if(quickDraw<gestalt8BitQD){
  82.         i=0;
  83.         CopyQuickDrawGlobals();                // Make sure qd is valid
  84.         r=qd.screenBits.bounds;
  85.         r.top+=LMGetMBarHeight();
  86.     }else{
  87.         if(device==NULL){
  88.             for(i=0;GetScreenDevice(i)!=NULL;i++)SquareCorners(GetScreenDevice(i));
  89.             return;
  90.         }
  91.         i=GetScreenIndex(device);
  92.         if(i>=MAX_SCREENS)return;
  93.         r=(*device)->gdRect;
  94.         if(device==GetMainDevice())r.top+=LMGetMBarHeight();
  95.     }
  96.     cornerRgn[i]=NewRgn();
  97.     RectRgn(cornerRgn[i],&r);
  98.     DiffRgn(cornerRgn[i],GetGrayRgn(),cornerRgn[i]);
  99.     if(EmptyRgn(cornerRgn[i]))return;
  100.     UnionRgn(GetGrayRgn(),cornerRgn[i],GetGrayRgn());
  101.     PaintBehind((WindowPeek)FrontWindow(),cornerRgn[i]);
  102.     CalcVisBehind((WindowPeek)FrontWindow(),cornerRgn[i]);
  103. }
  104.  
  105. void RestoreCorners(GDHandle device)
  106. // Restore rounding to this screen.
  107. // If NULL then applies to all screens.
  108. {
  109.     int i;
  110.     long quickDraw;
  111.     
  112.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  113.     if(quickDraw<gestalt8BitQD){
  114.         i=0;
  115.     }else{
  116.         if(device==NULL){
  117.             for(i=0;GetScreenDevice(i)!=NULL;i++)RestoreCorners(GetScreenDevice(i));
  118.             return;
  119.         }
  120.         i=GetScreenIndex(device);
  121.         if(i>=MAX_SCREENS)return;
  122.     }
  123.     if(cornerRgn[i]!=NULL){
  124. //        CopyQuickDrawGlobals();            // Make sure qd is valid.
  125. //        FillRgn(cornerRgn[i],(ConstPatternParam)&qd.black);    // don't know what port it belongs to
  126.         DiffRgn(GetGrayRgn(),cornerRgn[i],GetGrayRgn());
  127.         DisposeRgn(cornerRgn[i]);
  128.         cornerRgn[i]=NULL;
  129.     }
  130. }
  131.  
  132. void UnclipScreen(GDHandle device)
  133. {
  134.     long quickDraw;
  135.  
  136.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  137.     if(quickDraw<gestalt8BitQD || device==GetMainDevice())HideMenuBar();
  138.     SquareCorners(device);
  139. }
  140.  
  141. void RestoreScreenClipping(GDHandle device)
  142. {
  143.     long quickDraw;
  144.  
  145.     RestoreCorners(device);
  146.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  147.     if(quickDraw<gestalt8BitQD || device==GetMainDevice())ShowMenuBar();
  148. }